/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package miage.rest.validation;


/**
 *
 * @author marya
 */
public class RegexValidator extends AbstractValidator{

        private String regex;
        
        public RegexValidator(String regex){
            super();
            this.regex = regex;
        }

        @Override
        public boolean isValid(String data){
            if(!data.matches(regex)){
                addMessage("Exception occured : data doesn't matches string regular expression expected");
                return false;
            }
            return true;
        }

        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final RegexValidator other = (RegexValidator) obj;
            if ((this.regex == null) ? (other.regex != null) : !this.regex.equals(other.regex)) {
                return false;
            }
            return true;
        }

        @Override
        public int hashCode() {
            int hash = 3;
            hash = 79 * hash + (this.regex != null ? this.regex.hashCode() : 0);
            return hash;
        }


}
